<?php
/*
 *   This file is part of poat.
 *
 *   poat is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   poat is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with poat.  If not, see <http://www.gnu.org/licenses/>.
 */
 
$fpos = strrpos(dirname(__FILE__), "/");
if ($fpos<=0) {
	$fpos = strrpos(dirname(__FILE__), "\\");
}
define('ROOT_PATH',substr(dirname(__FILE__), 0, $fpos)."/");

if ($_GET['op']=='setup') {
	include_once(ROOT_PATH."includes/common.php");
	require_once(ROOT_PATH."class/files.class.php");
	require_once(ROOT_PATH."class/history.class.php");
	require_once(ROOT_PATH."class/project.class.php");
	require_once(ROOT_PATH."class/team.class.php");
	
	$subprj = new project;
	$subprj->id = $param['sid'];
	$loader->get($subprj);
	
	$prj = new project;
	$prj->id = $subprj->parent;
	$loader->get($prj);
	
	$team = new team;
	$team->id=$param['teamid'];
	$loader->get($team);
	
	$update = $param['update'];
	include(ROOT_PATH."includes/setupfilescreator.php");
	$db->close();
} elseif ($_GET['op']=='done') {
	include_once(ROOT_PATH."includes/common.php");
	
	require_once(ROOT_PATH."class/project.class.php");

	$tm->assign('message','Finished.');
	$content = $tm->display('getfiles.tpl');
	
	$db->close();		
} else {
	
	require_once(ROOT_PATH."class/team.class.php");
	require_once(ROOT_PATH."class/project.class.php");

	$tfiles = FILES.PROJECT_PREFIX.$param['id'];
	$thistory = HISTORY.PROJECT_PREFIX.$param['id'];
	
	if (!$db->exists($tfiles)) {
		$query = "CREATE TABLE ".$tfiles." (id INT(11) auto_increment NOT NULL, PRIMARY KEY(id), name VARCHAR(255) NOT NULL, path VARCHAR(255) NOT NULL, comment VARCHAR(255),statusid VARCHAR(10) NOT NULL, userid VARCHAR(20), teamid int(11) NOT NULL, prjid int(11) NOT NULL, lastupdate DATETIME NULL, chstamp VARCHAR(50) NULL, translated int(11) NULL, fuzzy int(11) NULL, untranslated int(11) NULL, autoflag TINYINT(4) NOT NULL DEFAULT 0) ENGINE=MyISAM DEFAULT CHARSET=UTF8";
		$db->query($query);
		$query = "CREATE TABLE ".$thistory." (id INT(11) auto_increment NOT NULL,fileid INT(11) NOT NULL,comment VARCHAR(255),statusid VARCHAR(10) NOT NULL, userid VARCHAR(20),date DATETIME NULL,PRIMARY KEY(id)) ENGINE=MyISAM DEFAULT CHARSET=UTF8";
		$db->query($query);
	}

	$list = array();
	foreach($param[teamid] as $tid) {
		$team = new team;
		$team->id=$tid;
		array_push($list,$team);
	}
	
	$tm->assign('update',$param['update'] == "true" ? "true" : "false");	
	$tm->assign('list',$list);
	$tm->assign('projectid',$param['id']);
	$tm->assign('sid',$param['sid']);
	$content = $tm->fetch('setupfiles.tpl');
	
	$tm->assign('content',$content);
}



?>
